package com.sailfish.springbootdemo.dao.db1;

import com.sailfish.springbootdemo.common.DB1TableName;
import com.sailfish.springbootdemo.pojo.db1.LineBaseBigType;
import com.sailfish.springbootdemo.pojo.db1.LineTechBigType;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface LineTechBigTypeDao {

    /**
     * 查询所有的
     *
     * @param searchValue
     * @return
     */
    @Results(id = "lineTechBigTypeResultMap", value = {
            @Result(column = "line_tech_big_type_id", property = "lineTechBigTypeId", jdbcType = JdbcType.INTEGER),
            @Result(column = "line_tech_big_type_name", property = "lineTechBigTypeName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "sort", property = "sort", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "line_level_ids", property = "lineLevelIds", jdbcType = JdbcType.VARCHAR),
    })
    @Select("<script>" +
            "select * from " + DB1TableName.LINE_TECH_BIG_TYPE + " where 1 = 1 " +
            "<if test='searchValue != null and searchValue != \"\" '>" +
            " and line_tech_big_type_name like CONCAT('%',#{searchValue},'%')" +
            "</if>" +
            " order by sort" +
            "</script>")
    List<LineTechBigType> getAllLineTechBigType(@Param("searchValue") String searchValue);

    @ResultMap(value = "lineTechBigTypeResultMap")
    @Select("select * from " + DB1TableName.LINE_TECH_BIG_TYPE + " where line_tech_big_type_name = #{lineTechBigTypeName}")
    List<LineTechBigType> getLineTechBigTypeByName(@Param("lineTechBigTypeName") String lineTechBigTypeName);

    /**
     * 根据id查询
     *
     * @param lineTechBigTypeId
     * @return
     */
    @Select("select * from " + DB1TableName.LINE_TECH_BIG_TYPE + " where line_tech_big_type_id = #{lineTechBigTypeId}")
    @ResultMap(value = "lineTechBigTypeResultMap")
    LineTechBigType getLineTechBigTypeById(@Param("lineTechBigTypeId") Integer lineTechBigTypeId);

    /**
     * 判断有没有重复的
     *
     * @return
     */
    @ResultMap(value = "lineTechBigTypeResultMap")
    @Select("<script>" +
            "select * from " + DB1TableName.LINE_TECH_BIG_TYPE + " where line_tech_big_type_name = #{lineTechBigTypeName} " +
            "<if test='lineTechBigTypeId != null and lineTechBigTypeId != \"\" '>" +
            " and line_tech_big_type_id != #{lineTechBigTypeId}" +
            "</if>" +
            "</script>")
    List<LineTechBigType> judgeUniqueLineTechBigType(@Param("lineTechBigTypeId") Integer lineTechBigTypeId, @Param("lineTechBigTypeName") String lineTechBigTypeName);

    /**
     * 新增
     *
     * @param lineTechBigType
     * @return
     */
    @Insert("insert into " + DB1TableName.LINE_TECH_BIG_TYPE + "(line_tech_big_type_name,status,sort,create_time,line_level_ids) values " +
            "(#{lineTechBigType.lineTechBigTypeName},#{lineTechBigType.status},#{lineTechBigType.sort},#{lineTechBigType.createTime},#{lineTechBigType.lineLevelIds})")
    Integer addLineTechBigType(@Param("lineTechBigType") LineTechBigType lineTechBigType);

    /**
     * 更新
     *
     * @param lineTechBigType
     * @return
     */
    @Update("<script>" +
            "update " + DB1TableName.LINE_TECH_BIG_TYPE +
            "<set>" +
            "<if test='lineTechBigType.lineTechBigTypeName != null and lineTechBigType.lineTechBigTypeName != \"\" '>" +
            " line_tech_big_type_name = #{lineTechBigType.lineTechBigTypeName}," +
            "</if>" +
            "<if test='lineTechBigType.lineLevelIds != null and lineTechBigType.lineLevelIds != \"\" '>" +
            " line_level_ids = #{lineTechBigType.lineLevelIds}," +
            "</if>" +
            "<if test='lineTechBigType.updateTime != null '>" +
            " update_time = #{lineTechBigType.updateTime}," +
            "</if>" +
            "</set>" +
            " where line_tech_big_type_id = #{lineTechBigType.lineTechBigTypeId}" +
            "</script>")
    Integer updateLineTechBigType(@Param("lineTechBigType") LineTechBigType lineTechBigType);

    /**
     * 删除
     *
     * @param lineTechBigTypeId
     * @return
     */
    @Delete("delete from " + DB1TableName.LINE_TECH_BIG_TYPE + " where line_tech_big_type_id = #{lineTechBigTypeId}")
    Integer deleteLineTechBigType(@Param("lineTechBigTypeId") Integer lineTechBigTypeId);
}
